const Service = require("egg").Service;

class VideoService extends Service{

    async getVideoList(){
        try{
            let videoList = this.app.model.Video.findAll({});
            return videoList
        }catch(error){
            return error
        }
    }

    async createVideo(body) {
        try {
            const video = {
                title: body.title,
                iframe_url: body.iframe_url,
                img: body.img,
            }
            await this.app.model.Video.create(video)
            return true;
        } catch (error) {
            return false;
        }
    }

    async updateVideo(id,{title,iframe_url,img}){
        try {
            await this.app.model.Video.update( { 
                title,
                iframe_url,
                img
            },
            {
                where:{id:id}
            } )
            return true
        } catch (error) {
            return false
        }
    }

    async deleteVideo(id){
        try {
            await this.app.model.Video.destroy({where:{id:id}})
            return true
        } catch (error) {
            return false
        }
    }

    async getVideoDetail(id) {
        try {
            const video = await this.app.model.Video.findOne({
                where: {
                    id
                }
            })
            console.log("#################",video);
            return video.iframe_url
        } catch (error) {
            return null
        }
    }
}
module.exports = VideoService;